<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Admin</title>
</head>
<body>
    <form>
        <table>
            <tr>
                <td>
                    日期：
                </td>
                <td>
                    <input type="text" id="date" placeholder="请选择日期">
                </td>
            </tr>
            <tr>
                <td>
                    类型:
                </td>
                <td>
                    <input type="text" id="type" name="type" placeholder="请输入类型">
                </td>
            </tr>
            <tr>
                <td>
                    名称:
                </td>
                <td>
                    <input type="text" id="name" name="name" placeholder="请输入名称">
                </td>
            </tr>
            <tr>
                <td>
                    小结:
                </td>
                <td>
                    <input type="text" id="summary" name="summary" placeholder="请输入小结">
                </td>
            </tr>
            <tr>
                <td>
                    具体内容:
                </td>
                <td>
                    <input type="text" id="detail" name="detail" placeholder="请输入具体内容">
                </td>
            </tr>
            <tr>
                <td>
                海报:
                </td>
                <td>
                    <input type="text" id="postimg" name="postimg" placeholder="请输入海报地址">
                </td>
            </tr>
            <tr>
                <td>
                    <input type="reset" name="reset" id="reset" value="重填">
                </td>
                <td>
                    <input type="button" name="submit" id="submit" value="提交">
                </td>
            </tr>
        </table>
    </form>
    
    <script src="laydate.js"></script>
    <script>
        laydate.render({
        elem: '#date'//指定元素
        ,format: 'yyyy-MM-dd' //可任意组合
        ,showBottom: true
  });



  window.onload=function(){
	//
	var date=document.getElementById("date");
	var type=document.getElementById("type");
    var name=document.getElementById("name");
    var summary=document.getElementById("summary");
    var detail=document.getElementById("detail");
    var postimg=document.getElementById("postimg");
    var submit = document.getElementById('submit');
	submit.onclick=function(){
		loginUser("http://47.94.84.158:8080/write");
	}
	var xmlhttp;
	function loginUser(path){ 
		if(window.XMLHttpRequest){
			
			xmlhttp=new XMLHttpRequest();
		}else if(window.ActiveXObject()){
		    
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		xmlhttp.open("POST",path,true);
		
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		
		xmlhttp.send("date="+date.value+"&type="+type.value+"&name="+name.value+"&summary="+summary.value+"&detail="+detail.value+"&postimg="+postimg.value);
		
		xmlhttp.onreadystatechange=httpBack;
	}
	function httpBack(){
		
		if(xmlhttp.readyState==4){
         
			if(xmlhttp.status==200){
				var result=xmlhttp.responseText;
				if(result=="1"){
					alert("成功");
					//以键值对形式存储时的键
					// var strKey="username";
					// var storage=window.localStorage;
					// if(storage){
					// 	//本地存储，存储键值对
					// 	storage.setItem(strKey, name.value);
					// }else{
					// 	//cookie键值对存储
					// 	Cookie.write(strKey, name.value);
					// }
					// var path="http://localhost:8080/Book/main";
					// window.location.assign(path);
				}else if(result=="0"){
					alert("用户名或者密码错误");
				}
			}
		}
	}
}
    </script>
</body>
</html>